import java.util.Random;

public class demo10 {
    private static long x = 0;
    private static long y = 0;

    private static int[] nums = new int[10000000];
    public static void main(String[] args) throws InterruptedException {
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++) {
            nums[i] = new Random().nextInt(100) + 1;
        }
        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i = 0;i < 10000000;i += 2) {
                    x += nums[i];
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i = 1;i < 10000000;i += 2) {
                    y += nums[i];
                }
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long count = x + y;
        long Time = System.currentTimeMillis() - startTime;
        System.out.println("执行时间: " + Time);
        System.out.println("偶数下标和: " + x);
        System.out.println("奇数下标和: " + y);
        System.out.println("总数为: " + count);
    }
}
